$(function() {
	$('#form-register').validate({
		rules: {
			username: {
				required: true,
				maxlength: 15
			},
			password:  {
				required: true,
				minlength: 5
			},
			password_confirm:{
				required: true,
				equalTo: "#password"
			},
			email: {
				required: true,
				email: true,
				remote: '/profile/check/email/'
			},
			email_confirm: {
				required: true,
				equalTo: "#email"
			},
			first_name	: "required",
			last_name	: "required",
			address		: "required",
			province 	: "required",
			birtday 	: "required",
			postcode	: {
				required: true,
				number:  true,
				minlength: 5,
				maxlength: 5
			},
			telephone	: {
				required: true,
				number:  true,
				minlength: 10,
				maxlength: 10
				
			},
			captcha		: "required"
		},
 		messages: {
			username: {
				required: "<em>This field is required.</em>",
				maxlength: "<em>Please enter no more than 15 characters.</em>"
			},
			password: {
				required: "<em>This field is required.</em>",
				minlength: "<em>Please enter at least 5 characters.</em>"
			},
			password_confirm: {
				required: "<em>This field is required.</em>",
				minlength: "<em>Please enter at least 5 characters.</em>",
				equalTo:  "<em>Please enter the same password again.</em>" 
			},
			email: {
				required: "<em>This field is required.</em>",
				email: "<em>Please enter a valid email address.</em>",
				remote: "<em>อีเมล์ นี้ถูกใช้งานแล้วค่ะ</em>"
			},
			email_confirm: {
				required: "<em>This field is required.</em>",
				minlength: "<em>Please enter at least 5 characters.</em>",
				equalTo:  "<em>Please enter the same password again.</em>" 
			},
			first_name: {
				required: "<em>This field is required.</em>",
			},
			last_name: {
				required: "<em>This field is required.</em>",
			},
			address: {
				required: "<em>This field is required.</em>",
			},
			province:{
				required: "<em>This field is required.</em>",
			},
			birtday :{
				required: "<em>This field is required.</em>",
			},
			postcode :{
				required: "<em>This field is required.</em>",
				number: "<em>Please enter a valid number.</em>",
				minlength: "<em>Please enter at least 5 characters.</em>",
				maxlength: "<em>Please enter no more than 5 characters.</em>"
			},
			telephone :{
				required: "<em>This field is required.</em>",
				number: "<em>Please enter a valid number.</em>",
			minlength: "<em>Please enter at least 10 characters.</em>",
				maxlength: "<em>Please enter no more than 10 characters.</em>"
			},
			captcha :{
				required: "<em>This field is required.</em>",
			}
		}, 
		success: function(label) {
			label.html("&nbsp;").addClass("checked");
		}
	});
	
	$('#birtday').datepicker({
		 dateFormat: 'yy-mm-dd',
		 changeMonth: true,
		 changeYear: true,
		 maxDate: '+0d',
		 yearRange : 'c-80:c+0'
	});
	
	$('#refresh-captcha').click(function(){
		$('.captcha-img img').attr({'src':'/captcha/?='+new Date()})
		return false;
	});
	
//	onclick="this.src=this.src+'?='+new Date()" 
})